var mCity = undefined
var productCode = undefined
$(document).ready(function () {
    //加载长沙市下面的区县
    $.ajax({
        method: 'POST',
        url: '/csfy/intf.do',
        data: {
            method: 'getAddrs',
            parentId: 4301,
        },
        success: function (res) {
            if (res && res.code == 200) {
                var rows = res.rows || []
                var options = "<option value=''>请选择区县</option>"
                rows.map((item) => {
                    options += "<option value='" + item.name + "'>" + item.name + "</option>"
                })
                $(".addressCounty").html(options);
            }
        }
    })
    productCode = undefined
    var productCodeEle = document.querySelector(".t-product-value")
    if (productCodeEle && productCodeEle.innerHTML) {
        productCode = productCodeEle.innerHTML
    }
    //加载医院列表
    $.ajax({
        method: 'POST',
        url: '/csfy/intf.do',
        data: {
            method: 'getCustomers',
            addressCity: '长沙市',
            productCode: productCode
        },
        success: function (res) {
            if (res && res.code == 200) {
                var rows = res.rows || []
                var options = "<option value=''>请选择</option>"
                rows.map((item) => {
                    options += "<option value='" + item.customerCode + "'>" + item.customerName + "</option>"
                })
                if ($('#customerCode').combobox) {
                    //jsp页面设置送检单位列表
                    $('#customerCode').combobox('loadData', rows);
                } else {
                    //html页面设置送检单位
                    $("#customerCode").html(options);
                }
            }
        }
    })
})

//选择区县变化监听
function onAddressCountyChange(value) {
    var data = {
        method: 'getCustomers'
    }
    var addressCounty = value;
    if(addressCounty == '宁乡市'){
        addressCounty = '宁乡县';
    }
    if (addressCounty) {
        data.addressCounty = addressCounty;
    } else {
        data.addressCity = '长沙市';
    }
    if (productCode) {
        data.productCode = productCode;
    }
    $.ajax({
        method: 'POST',
        url: '/csfy/intf.do',
        data: data,
        success: function (res) {
            if (res && res.code == 200) {
                var rows = res.rows || []
                var options = "<option value=''>请选择</option>"
                rows.map((item) => {
                    options += "<option value='" + item.customerCode + "'>" + item.customerName + "</option>"
                })
                if ($('#customerCode').combobox) {
                    //jsp页面设置送检单位列表
                    $('#customerCode').combobox('loadData', rows);
                    setTimeout(function () { $('#customerCode').combobox("setValue", rows.length > 0 ? rows[0].customerCode : "") }, 100)
                } else {
                    //html页面设置送检单位
                    $("#customerCode").html(options);
                }
            }
        }
    })
}
